package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EProblemDao;
import com.hongxun.modules.eys.entity.EProblemEntity;
import com.hongxun.modules.eys.service.EProblemService;



@Service("eProblemService")
public class EProblemServiceImpl implements EProblemService {
	@Autowired
	private EProblemDao eProblemDao;
	
	@Override
	public EProblemEntity queryObject(String guid){
		return eProblemDao.queryObject(guid);
	}
	
	@Override
	public List<EProblemEntity> queryList(Map<String, Object> map){
		return eProblemDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return eProblemDao.queryTotal(map);
	}
	
	@Override
	public void save(EProblemEntity eProblem){
        if(eProblem.getGuid()==null||eProblem.getGuid().equals("")) {

		    eProblem.setGuid(UUID.randomUUID().toString());
        }
		eProblemDao.save(eProblem);
	}
	
	@Override
	public void update(EProblemEntity eProblem){
		eProblemDao.update(eProblem);
	}
	
	@Override
	public void delete(String guid){
		eProblemDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		eProblemDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<EProblemEntity> entities) {
		for (EProblemEntity d : entities) {
			if (d.getDatastate().equals("删除")) {
				eProblemDao.delete(d.getGuid());
			} else {
				EProblemEntity eProblemEntity = eProblemDao.queryObject(d.getGuid());
				if (eProblemEntity == null) {
					eProblemDao.save(d);
				} else {
					eProblemDao.update(d);
				}
			}
		}
	}
}
